**** Panel A


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear



drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.



****** CONSTRAINED: Line 1 ***

***** H=18 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/17 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 18 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)


	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==18
save "$path\Graphs_Tables\Table3_constrainedpanel_line1.dta", replace
restore
}





****** CONSTRAINED: Line 2 ***

***** H=24 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/23 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 24 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==24
save "$path\Graphs_Tables\Table3_constrainedpanel_line2.dta", replace
restore
}



****** UNCONSTRAINED: Line 1 ***
**** H=18 ***


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


***** H=18 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/17 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 18 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'

replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==18
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line1.dta", replace
restore
}


***** H=24 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/23 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 24 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==24
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line2.dta", replace
restore
}

******* Panel B *****

***** 2Y ****


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear



drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_2Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_2Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.



****** CONSTRAINED: Line 3 ***

capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_constrainedpanel_line3.dta", replace
restore
}




****** UNCONSTRAINED: Line 3 ***


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


***** H=30 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line3.dta", replace
restore
}





***** 4Y ****


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_4Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_4Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.



****** CONSTRAINED: Line 4 ***

capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_constrainedpanel_line4.dta", replace
restore
}




****** UNCONSTRAINED: Line 4 ***


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


***** H=30 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'



replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line4.dta", replace
restore
}







****** 8Y


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_8Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_8Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.



****** CONSTRAINED: Line 5 ***

capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


/* On divise par le pass-through de long terme (h=30) de la régression baseline sur les stations à 6 ans */

areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_constrainedpanel_line5.dta", replace
restore
}




****** UNCONSTRAINED: Line 5 ***


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


***** H=30 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line5.dta", replace
restore
}




***** PANEL C:

**** Constrained, LT = 19-24, line 6


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.




capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/17 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_18
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 18 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_18
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==18
save "$path\Graphs_Tables\Table3_constrainedpanel_line6.dta", replace
restore
}




**** Non Constrained, LT = 19-24, line 6


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/17 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_18
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 18 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_18
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==18
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line6.dta", replace
restore
}




**** Constrained, LT = 25-30, line 7


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.




capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/23 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_24
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 24 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_24
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==24
save "$path\Graphs_Tables\Table3_constrainedpanel_line7.dta", replace
restore
}




**** Non Constrained, LT = 25-30, line 7


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/23 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_24
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 24 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_24
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==24
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line7.dta", replace
restore
}







**** Constrained, LT = 37-40, line 8


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

*gen t=(prix_ht==.)
drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.




capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/35 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_36
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 36 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_36
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==36
save "$path\Graphs_Tables\Table3_constrainedpanel_line8.dta", replace
restore
}




**** Non Constrained, LT = 37-40, line 8


capture drop ratio
gen ratio=kurtosis/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(kur) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/35 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_36
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 36 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_36
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==36
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line8.dta", replace
restore
}







***** PANEL D



**** Constrained, kurtosis corrected 15: line 9


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=k_15/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.
gen r2=.
gen r2_a=.




capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	replace r2=e(r2)
replace r2_a=e(r2_a)

matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg r2 r2_a  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_constrainedpanel_line9.dta", replace
restore
}




**** Non Constrained, kurtosis corrected 15: line 9


capture drop ratio
gen ratio=k_15/freq

bysort id: gen first_obs=1 if _n==1

egen mean_kur_temp=mean(k_15) if first_obs==1
egen mean_freq_temp=mean(freq) if first_obs==1
egen mean_kur=mean(mean_kur_temp)
egen mean_freq=mean(mean_freq_temp)
drop mean_kur_temp mean_freq_temp first_obs

gen kur_demean=kur/mean_kur
gen freq_demean=freq/mean_freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.freq_demean c.kur_demean) c.local_shock10##(c.freq_demean c.kur_demean) c.m_dprix##(c.freq_demean c.kur_demean) c.l.d_dieselr##(c.freq_demean c.kur_demean) ///
 c.l2.d_dieselr##(c.freq_demean c.kur_demean) c.l3.d_dieselr##(c.freq_demean c.kur_demean) c.l4.d_dieselr##(c.freq_demean c.kur_demean) c.l5.d_dieselr##(c.freq_demean c.kur_demean) ///
		c.l.local_shock10##(c.freq_demean c.kur_demean)  c.l2.local_shock10##(c.freq_demean c.kur_demean) c.l3.local_shock10##(c.freq_demean c.kur_demean) c.l4.local_shock10##(c.freq_demean c.kur_demean) ///
		c.l5.local_shock10##(c.freq_demean c.kur_demean)	c.l.m_dprix##(c.freq_demean c.kur_demean)  c.l2.m_dprix##(c.freq_demean c.kur_demean) c.l3.m_dprix##(c.freq_demean c.kur_demean) ///
		c.l4.m_dprix##(c.freq_demean c.kur_demean) c.l5.m_dprix##(c.freq_demean c.kur_demean), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.freq_demean] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.kur_demean] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
preserve
keep coeff1_reg coeff2_reg coeff3_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg df_reg num_obs
gen name="`i'"
gen charact="unconstrained"
keep if num_obs==30
save "$path\Graphs_Tables\Table3_unconstrainedpanel_line9.dta", replace
restore
}






****** Format Table 3 ***

**** Constrained ***

clear

use  "$path\Graphs_Tables\Table3_constrainedpanel_line1.dta", replace
append using "$path\Graphs_Tables\Table3_constrainedpanel_line2.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line3.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line4.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line5.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line6.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line7.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line8.dta"
append using "$path\Graphs_Tables\Table3_constrainedpanel_line9.dta"


gen id_col=_n

xpose, clear

drop if _n==1

set obs 18

capture drop col1
capture drop col2
capture drop col3
capture drop col4


gen col1=.
replace col1=v1[2] if _n==1
replace col1=v1[4] if _n==2
replace col1=v2[2] if _n==3
replace col1=v2[4] if _n==4

replace col1=v3[2] if _n==5
replace col1=v3[4] if _n==6
replace col1=v4[2] if _n==7
replace col1=v4[4] if _n==8

replace col1=v5[2] if _n==9
replace col1=v5[4] if _n==10
replace col1=v6[2] if _n==11
replace col1=v6[4] if _n==12

replace col1=v7[2] if _n==13
replace col1=v7[4] if _n==14
replace col1=v8[2] if _n==15
replace col1=v8[4] if _n==16

replace col1=v9[2] if _n==17
replace col1=v9[4] if _n==18



gen col2=.
replace col2=v1[1] if _n==1
replace col2=v1[3] if _n==2
replace col2=v2[1] if _n==3
replace col2=v2[3] if _n==4

replace col2=v3[1] if _n==5
replace col2=v3[3] if _n==6
replace col2=v4[1] if _n==7
replace col2=v4[3] if _n==8

replace col2=v5[1] if _n==9
replace col2=v5[3] if _n==10
replace col2=v6[1] if _n==11
replace col2=v6[3] if _n==12

replace col2=v7[1] if _n==13
replace col2=v7[3] if _n==14
replace col2=v8[1] if _n==15
replace col2=v8[3] if _n==16

replace col2=v9[1] if _n==17
replace col2=v9[3] if _n==18



gen col3=.
replace col3=v1[6] if _n==1
replace col3=v2[6] if _n==3

replace col3=v3[6] if _n==5
replace col3=v4[6] if _n==7

replace col3=v5[6] if _n==9
replace col3=v6[6] if _n==11

replace col3=v7[6] if _n==13
replace col3=v8[6] if _n==15

replace col3=v9[6] if _n==17

gen Panel="Panel A: Horizon" if _n==1
replace Panel="Panel B: Sample of gas stations" if _n==5
replace Panel="Panel C: Horizon of long term pass through" if _n==11
replace Panel="Panel D: Kurtosis corrected for heterogeneity" if _n==17



gen Var="H=18 days" if _n==1
replace Var=" H=24 days" if _n==3
replace Var="> 2 years" if _n==5
replace Var="> 4 years" if _n==7
replace Var="> 8 years" if _n==9
replace Var="19-24 days" if _n==11
replace Var="25-30 days" if _n==13
replace Var="37-40 days" if _n==15


drop v*


gen tstatcol1=.
gen tstatcol2=.




foreach i in 1 3 5 7 9 11 13 15 17 {
replace tstatcol1=col1[`i']/col1[`i'+1] if _n==`i'
replace tstatcol2=col2[`i']/col2[`i'+1] if _n==`i'
}

gen starscol1=""
gen starscol2=""


foreach i in 1 2 {
replace starscol`i'="***" if abs(tstatcol`i')>=2.58 & tstatcol`i'!=.
replace starscol`i'="**" if abs(tstatcol`i')<2.58 & abs(tstatcol`i')>=1.96 & tstatcol`i'!=.
replace starscol`i'="*" if abs(tstatcol`i')<1.96 & abs(tstatcol`i')>=1.64 & tstatcol`i'!=.
}

drop tstat*
rename col* coltemp*

foreach i in 1 2{
replace coltemp`i'=round(coltemp`i', 0.001)
tostring coltemp`i', gen(coltempbis`i') force format("%9.3f")  
egen col`i'=concat(coltempbis`i' starscol`i')
}


rename col1 ShockxRatio
rename col2 Shock_constr
rename coltemp3 R2_constr

gen num_obs=_n

keep Var ShockxRatio Shock_constr R2_constr num_obs
order Var ShockxRatio Shock_constr R2_constr num_obs
save "$path\Graphs_Tables\Table3_constrainedpanel_ALL.dta", replace





**** Unconstrained ***

clear

use  "$path\Graphs_Tables\Table3_unconstrainedpanel_line1.dta", replace
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line2.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line3.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line4.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line5.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line6.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line7.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line8.dta"
append using "$path\Graphs_Tables\Table3_unconstrainedpanel_line9.dta"


gen id_col=_n

xpose, clear

drop if _n==1

set obs 18

capture drop col1
capture drop col2
capture drop col3
capture drop col4



gen col1=.
replace col1=v1[2] if _n==1
replace col1=v1[5] if _n==2
replace col1=v2[2] if _n==3
replace col1=v2[5] if _n==4

replace col1=v3[2] if _n==5
replace col1=v3[5] if _n==6
replace col1=v4[2] if _n==7
replace col1=v4[5] if _n==8

replace col1=v5[2] if _n==9
replace col1=v5[5] if _n==10
replace col1=v6[2] if _n==11
replace col1=v6[5] if _n==12

replace col1=v7[2] if _n==13
replace col1=v7[5] if _n==14
replace col1=v8[2] if _n==15
replace col1=v8[5] if _n==16

replace col1=v9[2] if _n==17
replace col1=v9[5] if _n==18



gen col2=.
replace col2=v1[3] if _n==1
replace col2=v1[6] if _n==2
replace col2=v2[3] if _n==3
replace col2=v2[6] if _n==4

replace col2=v3[3] if _n==5
replace col2=v3[6] if _n==6
replace col2=v4[3] if _n==7
replace col2=v4[6] if _n==8

replace col2=v5[3] if _n==9
replace col2=v5[6] if _n==10
replace col2=v6[3] if _n==11
replace col2=v6[6] if _n==12

replace col2=v7[3] if _n==13
replace col2=v7[6] if _n==14
replace col2=v8[3] if _n==15
replace col2=v8[6] if _n==16

replace col2=v9[3] if _n==17
replace col2=v9[6] if _n==18




gen col3=.
replace col3=v1[1] if _n==1
replace col3=v1[4] if _n==2
replace col3=v2[1] if _n==3
replace col3=v2[4] if _n==4

replace col3=v3[1] if _n==5
replace col3=v3[4] if _n==6
replace col3=v4[1] if _n==7
replace col3=v4[4] if _n==8

replace col3=v5[1] if _n==9
replace col3=v5[4] if _n==10
replace col3=v6[1] if _n==11
replace col3=v6[4] if _n==12

replace col3=v7[1] if _n==13
replace col3=v7[4] if _n==14
replace col3=v8[1] if _n==15
replace col3=v8[4] if _n==16

replace col3=v9[1] if _n==17
replace col3=v9[4] if _n==18




gen col4=.
replace col4=v1[8] if _n==1
replace col4=v2[8] if _n==3

replace col4=v3[8] if _n==5
replace col4=v4[8] if _n==7

replace col4=v5[8] if _n==9
replace col4=v6[8] if _n==11

replace col4=v7[8] if _n==13
replace col4=v8[8] if _n==15

replace col4=v9[8] if _n==17

gen Panel="Panel A: Horizon" if _n==1
replace Panel="Panel B: Sample of gas stations" if _n==5
replace Panel="Panel C: Horizon of long term pass through" if _n==11
replace Panel="Panel D: Kurtosis corrected for heterogeneity" if _n==17



gen Var="H=18 days" if _n==1
replace Var=" H=24 days" if _n==3
replace Var="> 2 years" if _n==5
replace Var="> 4 years" if _n==7
replace Var="> 8 years" if _n==9
replace Var="19-24 days" if _n==11
replace Var="25-30 days" if _n==13
replace Var="37-40 days" if _n==15





drop v*


gen tstatcol1=.
gen tstatcol2=.
gen tstatcol3=.



foreach i in 1 3 5 7 9 11 13 15 17 {
replace tstatcol1=col1[`i']/col1[`i'+1] if _n==`i'
replace tstatcol2=col2[`i']/col2[`i'+1] if _n==`i'
replace tstatcol3=col3[`i']/col3[`i'+1] if _n==`i' 
}

gen starscol1=""
gen starscol2=""
gen starscol3=""


foreach i in 1 2 3  {
replace starscol`i'="***" if abs(tstatcol`i')>=2.58 & tstatcol`i'!=.
replace starscol`i'="**" if abs(tstatcol`i')<2.58 & abs(tstatcol`i')>=1.96 & tstatcol`i'!=.
replace starscol`i'="*" if abs(tstatcol`i')<1.96 & abs(tstatcol`i')>=1.64 & tstatcol`i'!=.
}

drop tstat*
rename col* coltemp*

foreach i in 1 2 3 {
replace coltemp`i'=round(coltemp`i', 0.001)
tostring coltemp`i', gen(coltempbis`i') force format("%9.3f")  
egen col`i'=concat(coltempbis`i' starscol`i')
}



rename col1 ShockxFreq
rename col2 ShockxKurtosis
rename col3 Shock_uconstr
rename coltemp4 R2_uconstr

keep Panel Var ShockxFreq ShockxKurtosis Shock_uconstr R2_uconstr
order Panel Var ShockxFreq ShockxKurtosis Shock_uconstr R2_uconstr
save "$path\Graphs_Tables\Table3_unconstrainedpanel_ALL.dta", replace

gen num_obs=_n
merge 1:1 num_obs using "$path\Graphs_Tables\Table3_constrainedpanel_ALL.dta"
drop _merge
drop num_obs


replace R2_uconstr=round(R2_uconstr, 0.001)
format %9.3f  R2_uconstr

replace R2_constr=round(R2_constr, 0.001)
format %9.3f  R2_constr

order Panel Var ShockxRatio Shock_constr R2_constr ShockxFreq ShockxKurtosis Shock_uconstr R2_uconstr

save "$path\Graphs_Tables\Table3_edited.dta", replace


